<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ page
	import="com.onlineMIS.common.Common_util,java.util.Date,java.text.SimpleDateFormat"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>禧乐仓连锁店管理信息系统</title>
<%@ include file="../../common/Style.jsp"%>

<script>

$(document).ready(function(){
	parent.$.messager.progress('close'); 
	
	$('#headqCustId').combobox('setValue', '');

	var params = $.serializeObject($('#preGenReportForm'));
	
	$('#dataGrid').datagrid({
		url : 'headQReportJSON!getUnitSalesReportInfo',
		queryParams: params,
		fit : true,
		fitColumns : false,
		pagination : false,
		pageSize : 20,
		pageList : [ 20, 30],
		border : false,
		checkOnSelect : false,
		selectOnCheck : false,
		singleSelect:true,
		showFooter:true,
		rownumbers:true,
		nowrap : false,
		columns : [ [
			{field:'clientId', width:70,title:'客户账号',fixed:true},
			{field:'clientName', width:170,title:'客户姓名',fixed:true,
				formatter: function (value, row, index){
					return row.clientName;
				}},
			{field:'storeName', width:170,title:'店铺名称'},
			{field:'totalQuantity', width:120,title:'销售数量 A'},
			{field:'totalRetailPrice', width:120,title:'成本金额',
				formatter: function (value, row, index){
					return row.totalRetailPrice.toFixed(2);
				}},
			{field:'totalWholePrice', width:120,title:'销售金额 B',
				formatter: function (value, row, index){
					return row.totalWholePrice.toFixed(2);
				}},	
			{field:'totalQuantityR', width:120,title:'退货数量 C'},
			{field:'totalRetailPriceR', width:120,title:'成本金额',
				formatter: function (value, row, index){
					return row.totalRetailPriceR.toFixed(2);
				}},
			{field:'totalWholePriceR', width:120,title:'退货金额 D',
					formatter: function (value, row, index){
						return row.totalWholePriceR.toFixed(2);
					}},	
			{field:'sumQuantity', width:120,title:'合计数量 A-C'},
			{field:'sumWholePrice', width:120,title:'合计销售金额 B-D',
				formatter: function (value, row, index){
					return row.sumWholePrice.toFixed(2);
				}},
			{					
				field : 'action',
				title : '详情',
				width : 70,
				formatter : function(value, row, index) {
					var str = '';
					var url = "<%=request.getContextPath()%>/action/headqReportJSP!unitSalesReportDetails?formBean.orderIds=" + row.orderIds;
					if(row.clientId !=0){
						str += $.formatString('<a href="#" onclick="addTab6(\'{0}\',\'{1}\');"><img border="0" src="{2}" title="详情"/></a>', url, '客户 ' + row.clientId,'<%=request.getContextPath()%>/conf_files/easyUI/themes/icons/text_1.png');									
					}
					return str;
				}
			}													
		]],
		toolbar : '#toolbar',
	});
});


	//查询报表
	function generateReport() {
		var isSuccess = false;
		var yearInfo = $("#yearId").combobox('getValue');
		var quarter = $("#quarterId").combobox('getValue');
		var brand = $("#brandId").combobox('getValue');
		var barcode = $("#barcode").textbox('getValue');
		
		//校验条码
		var reg = new RegExp("^[0-9]*$"); 
	
		if(!reg.test(barcode)){  
			$.messager.alert('提示', '条码含有非法字符，请输入正确的条形码！', 'warning');
			return;
		}else{
			isSuccess = true;
		}
		
		if((barcode != null && barcode != "")  && barcode.length != 12){
			$.messager.alert('提示', '请输入长度为12位的条形码！', 'warning');
			return;
		}else{
			isSuccess = true;
		}
		
		
		if(brand !=null && brand != ""){
			if ((yearInfo != null || yearInfo != "")
					&& (quarter == null || quarter == "")) {
				$.messager.alert('提示', '请选择货品年份信息', 'warning');
			} else if ((yearInfo == null || yearInfo == "")
					&& (quarter != null || quarter != "")) {
				$.messager.alert('提示', '请选择货品季度信息', 'warning');
			} else{
				isSuccess = true;
			}
		}else{
			if ((yearInfo == null || yearInfo == "")
					&& (quarter == null || quarter == "")) {
				isSuccess = true;
			} 
		}
		
		if (isSuccess) {
			var params = $.serializeObject($('#preGenReportForm'));
			$('#dataGrid').datagrid('load', params);
		}
	}

	//下载单据
	function downloadReport() {
		document.preGenReportForm.action = "headqReportJSP!downloadReportInfo";
		document.preGenReportForm.submit();
	}

	function BSkeyDown(e) {

		var ieKey = event.keyCode;

		if (ieKey == 13) {
			if (event.srcElement.id == "custName") {
				searchCust();
				event.returnValue = false;
			}
		}
	}

	//限制年份下拉框
	function onChangeYear() {
		var yearInfo = $("#yearId").combobox('getValue');
		if (yearInfo == null || yearInfo == "") {
			$.messager.alert('提示', '请先选择货品年份信息', 'warning');
		}
	}	
	
	function selectCust(){		
		var cust = $("#headqCustId").combobox('getValue');
		if(cust != null && cust !=""){
			$("#tagLevelOne").combobox('disable');
			$("#tagLevelTwo").combobox('disable');
			$("#tagLevelThree").combobox('disable');
			$("#tagLevelFour").combobox('disable');
		}else{
			$("#tagLevelOne").combobox('enable');
			$("#tagLevelTwo").combobox('enable');
			$("#tagLevelThree").combobox('enable');
			$("#tagLevelFour").combobox('enable');
		}				
	}
	
	function selectBarcode(){
		var barcode = $("#barcode").textbox('getValue');
		if(barcode != null && barcode !=""){
			$("#yearId").textbox('disable');
			$("#quarterId").textbox('disable');
			$("#brandId").textbox('disable');
		}else{
			$("#yearId").textbox('enable');
			$("#quarterId").textbox('enable');
			$("#brandId").textbox('enable');
		}
	}

	document.onkeydown = BSkeyDown;
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',border:false" style="height: 120px;">
			<s:form id="preGenReportForm" name="preGenReportForm" action="" theme="simple" method="POST">
				<table width="100%" border="0">
					<tr>
						<td colspan="13"><strong>请选择查询条件：</strong></td>
					</tr>
					<tr class="InnerTableContent">
						<td width="1%" height="40">&nbsp;</td>
						<td width="3%" align="center"><strong>日期:</strong></td>
						<td width="4%"><s:textfield id="startDate"
								name="formBean.startDate" cssClass="easyui-datebox"
								data-options="width:120,editable:false" /> &nbsp; 至&nbsp; <s:textfield
								id="endDate" name="formBean.endDate"
								cssClass="easyui-datebox"
								data-options="width:120,editable:false" /></td>
						<td width="2%" align="center"><strong>客户:</strong></td>
						<td width="3%">
							<s:select size="1" cssClass="easyui-combobox"  style="width:85%" data-options="prompt:'请选择客户',onChange:function(a,b){selectCust();}" headerKey="" headerValue="" id="headqCustId" list="uiBean.custs" listKey="id" name="formBean.cust.id" listValue="name" />							
						</td>

						<td width="3%" align="center"><strong>一组标签：</strong></td>
						<td width="2%"><s:select size="1" cssClass="easyui-combobox"  style="width:85%" data-options="prompt:'请选择第一组标签'" headerKey="" headerValue="" id="tagLevelOne" list="uiBean.tagLevelOne" listKey="id" name="formBean.tagLevelOne" listValue="tagName" /></td>
						<td width="3%" align="center"><strong>二组标签：</strong></td>
						<td width="2%" ><s:select size="1" cssClass="easyui-combobox"  style="width:85%" data-options="prompt:'请选择第二组标签'" headerKey="" headerValue="" id="tagLevelTwo" list="uiBean.tagLevelTwo" listKey="id" name="formBean.tagLevelTwo" listValue="tagName" /></td>
						<td width="3%" align="center"><strong>三组标签：</strong></td>
						<td width="2%" ><s:select size="1" cssClass="easyui-combobox"  style="width:85%" data-options="prompt:'请选择第三组标签'" headerKey="" headerValue="" id="tagLevelThree" list="uiBean.tagLevelThree" listKey="id" name="formBean.tagLevelThree" listValue="tagName" /></td>
						<td width="3%" align="center"><strong>四组标签：</strong></td>
						<td width="2%" ><s:select size="1" cssClass="easyui-combobox"  style="width:85%" data-options="prompt:'请选择第四组标签'" headerKey="" headerValue="" id="tagLevelFour" list="uiBean.tagLevelFour" listKey="id" name="formBean.tagLevelFour" listValue="tagName" /></td>	 					
					</tr>
					<tr>
						<td width="1%" height="40">&nbsp;</td>
						<td align="center"><strong>条码:</strong></td>
						<td >
							<s:textfield id="barcode"  style="width:83%" cssClass="easyui-textbox" data-options="prompt:'请输入货品条码',onChange:function(a,b){selectBarcode();}" name="formBean.barcode" size="9" />
						</td>
						<td align="center"><strong>货品年份:</strong></td>
						<td>
							<s:select size="1" cssClass="easyui-combobox" style="width:85%" data-options="prompt:'请选择年份'" id="yearId" list="uiBean.years" listKey="year_ID" name="formBean.year.year_ID" listValue="year" headerKey="" headerValue="" />							
						</td>
						<td align="center"><strong>货品季度:</strong></td>
						<td>
							<s:select size="1" cssClass="easyui-combobox" style="width:85%" data-options="prompt:'请选择季度',editable:false" id="quarterId" list="uiBean.quarters" listKey="quarter_ID" name="formBean.quarter.quarter_ID" listValue="quarter_Name" headerKey="" headerValue=""/>
						</td>
						<td align="center"><strong>货品品牌:</strong></td>
						<td>
							<s:select size="1" cssClass="easyui-combobox" style="width:85%" data-options="prompt:'请选择品牌'" id="brandId" list="uiBean.brands" listKey="brand_ID" name="formBean.brand.brand_ID" listValue="brand_Name"  headerKey="" headerValue=""/>
						</td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>
					
				</table>
			</s:form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid" border="0">
			</table>
			<div id="toolbar" style="display: none;">
				<a onclick="generateReport();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="iconCls:'icon-search',plain:true">查询报表</a>
				 <a
					onclick="downloadReport();" href="javascript:void(0);"
					class="easyui-linkbutton"
					data-options="plain:true,iconCls:'icon-save'">下载报表</a>	
			</div>
		</div>
	</div>
</body>
</html>